#include "../../framework/framework.h"
#include "../inc/xVertex.h"
#include "../inc/xDevice.h"
#include "../inc/xMedia.h"
namespace Sky
{
	
	TUint xVertex::ms_Usage = D3DUSAGE_DYNAMIC;
	D3DPOOL xVertex::ms_Pool = D3DPOOL_DEFAULT;
	TUint xVertex::ms_Fvf = 0;

	xVertex::xVertex()
	{
		Initialise();
	}

	xVertex::~xVertex()
	{
		Finalise();
	}
	
	TResult xVertex::onCreate( xDxApp* app )
	{
		return XE_OK;
	}

	TResult xVertex::onDelete( xDxApp* app )
	{
		Finalise();
		return XE_OK;
	}

	TResult xVertex::onCreate( xDevice* device )
	{
		TResult hr;
		if(vNull != m_Res)
		{
			onDelete(device);
		}
		hr = device->getDevice9()->CreateVertexBuffer(m_Length,m_Usage,m_Fvf,m_Pool,&m_Res,vNull);
		if(FAILED(hr)){
			myDx_Trace_hr0(M,hr,"xVertex::onCreate() failed");
			return XE_APICALL;
		} // if(FAILED(hr))
		return XE_OK;
	}

	TResult xVertex::onReset( xDevice* device )
	{
		if(vNull != m_Res)return XE_OK;
		return onCreate(device);
	}

	TResult xVertex::onLost( xDevice* device )
	{
		return onDelete(device);
	}


	TResult xVertex::onDelete( xDevice* device )
	{
		SAFE_RELEASE(m_Res);
		return XE_OK;
	}	

	TVoid xVertex::Initialise()
	{
		m_Usage = 0;
		m_Pool = D3DPOOL_DEFAULT;
	}

	TVoid xVertex::Finalise()
	{

	}
}
